package mo.leetcode_top;

import java.util.Arrays;

public class L189 {

    public void rotate(int[] nums, int k) {
        int length = nums.length;
        if (k % length == 0) {
            return;
        }
        int start = 0;
        int index = 0;
        int pre = 0;
        int cur = nums[0];
        for (int i = 0; i < length; i++) {
            pre = cur;
            index = (index + k) % length;
            cur = nums[index];
            nums[index] = pre;
            if (index == start) {
                index = ++start;
                cur = nums[index];
            }
        }

    }

    public static void main(String[] args) {
        L189 test = new L189();
        int[] nums = new int[]{1,2,3,4,5,6,7};
        test.rotate(nums, 3);
        System.out.println(Arrays.toString(nums));
    }

}
